package org.swift.mashup.engine.concurrency.execution;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;

import org.swift.mashup.engine.concurrency.agenda.ActionException;

public class ExecutionOutput {
	private Map<String, Collection<Object>> results = null;
	private Set<ActionException> errors = Collections.<ActionException>emptySet();
	
	public ExecutionOutput (Map<String, Collection<Object>> results){
		this.results = Collections.unmodifiableMap(results);
	}
	
	public ExecutionOutput (Map<String, Collection<Object>> results,
			Set<ActionException> errors){
		this(results);
		this.errors = Collections.unmodifiableSet(errors);
	}
	
	public Map<String,Collection<Object>> getResults(){
		return this.results;
	}
	
	public Set<ActionException> getErrors(){
		return this.errors;
	}
	
	public boolean hasErrors(){
		return this.errors.size() > 0;
	}
	
	public ActionException getFirstException(){
		if (!this.hasErrors()){
			throw new IllegalStateException("No exceptions exist.");
		}
		return this.errors.iterator().next();
	}
}